 <div class="book">   
   <form method="post" action="{:url('Show/sendemail')}" data-type="ajax">
   <input type="hidden" id="token" name="__hash__" value="" />
   <p><input type="text" name="name" id="name" class="intext" placeholder="姓名" ></p>
   <p><input type="text" name="phone" id="phone" class="intext i2" placeholder="手机" ></p>
   <p><input type="text" name="email" id="email" class="intext" placeholder="邮箱" ></p>
   <p><input type="text" name="address" id="address" class="intext i2" placeholder="地址" ></p>
   <p><textarea class="intext te" name="content" id="content" placeholder="留言内容" style="height:120px;"></textarea></p>
      <p><input type="submit" class="sbtn" value="提交留言" ></p>
   </form>   
  </div>

<script src="__PUBLIC__/public/layer/layer.js"></script>
<script>
$(document).on('submit','form[data-type=ajax]',function(){
	var url = $(this).attr('action');
	var data = $(this).serializeArray();
	if($("#name").val()==""){ 
		layer.alert("请输入姓名");
		return false;
	}
	if($("#phone").val()==""){ 
		layer.alert("请输入手机");
		return false;
	}
	var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;	
	var phone = $("#phone").val();
	if (!phoneReg.test(phone)) {
		layer.msg('手机号码格式错误');
		return false;
	} 
	if($("#email").val()==""){ 
		layer.alert("请输入邮箱");
		return false;
	}
	var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if(!myreg.test($("#email").val())){
		layer.msg('邮箱格式错误');		
	   return false;
    }	
	if($("#content").val()==""){ 
		layer.alert("请输入内容");
		return false;
	}
	$.post(url,data,function(res){		
		if(res.code == 1){
			layer.alert(res.msg,function(){ window.location.reload(); });	
		}else{			
			layer.alert(res.msg);			
		}
	},"JSON");
	return false;
});
$(function(){
	$.get('/index/show/getToken.html',function(res){
		$("#token").val(res.__token__);
	},'json')
})
</script>